package com.kingdee.pda.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.kingdee.pda.R;
import com.kingdee.pda.entity.WarehouseLocation;
import com.kingdee.pda.util.ViewHolder;

/**
 * 移库信息列表适配器
 * Created by zhanlg
 * DATE 2021/5/29
 * TIME 10:44
 */
public class MoveLocationAdapter extends AbsBaseAdapter<WarehouseLocation> {

    public MoveLocationAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_item_move_location, null);
        }
        TextView tv_moveType = ViewHolder.get(convertView, R.id.tv_move_type);
        TextView tv_availableQty = ViewHolder.get(convertView, R.id.tv_available_qty);
        TextView tv_waitMove = ViewHolder.get(convertView, R.id.tv_wait_move);
        TextView tv_stockQty = ViewHolder.get(convertView, R.id.tv_stock_qty);

        WarehouseLocation location = getData().get(position);
        boolean moveOut = location.isMoveOut();
        tv_moveType.setText(moveOut ? "移出" : "移入");
        try {
            //如果是移出库位，则直接获取选中的库存状态显示
            if (moveOut && location.getSelectedStatusBean() != null) {
                tv_availableQty.setText(String.valueOf(location.getSelectedStatusBean().getAvailableQty()));
                tv_waitMove.setText(String.valueOf(location.getSelectedStatusBean().getWaitMoveQty()));
                tv_stockQty.setText(String.valueOf(location.getSelectedStatusBean().getStockQty()));
            } else { //如果是移入库位，则需计算所有的库存状态显示
                tv_availableQty.setText(String.valueOf(location.getAllAvailableQty()));
                tv_waitMove.setText(String.valueOf(location.getAllWaitMoveQty()));
                tv_stockQty.setText(String.valueOf(location.getAllStockQty()));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }
}
